package com.site.controller;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 基础控制器
 */
public abstract class BaseController {

    /**
     * 获取 ServletRequestAttributes
     * @return
     */
    protected ServletRequestAttributes getServletRequestAttributes(){
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }

    /**
     * 获取 HttpServletResponse
     * @return
     */
    protected HttpServletRequest getRequest(){
        return getServletRequestAttributes().getRequest();
    }

    /**
     * 获取 HttpServletResponse
     * @return
     */
    protected HttpServletResponse getResponse(){
        return getServletRequestAttributes().getResponse();
    }
}
